package IT.Servlet;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;
import IT.DataAccess.IDatCatalogoEstado;
import IT.DataAccess.DatCatalogoEstado;
import IT.Entities.CatalogoEstado;
import java.util.List;

public class ClienteTipoServlet extends HttpServlet {
   

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=ISO-8859-1");
        PrintWriter out = response.getWriter();
        try {
            IDatCatalogoEstado oDatEstado;
            List<CatalogoEstado> oLista;
            
            if(request.getParameter("nTipo")!=null){                
                if(request.getParameter("nTipo").trim().equals("1")){               
                    out.printf("<option value='%1s'>%2s</option>", "1", "RUC");                
                    
                }else if(request.getParameter("nTipo").trim().equals("2")){
                    oDatEstado=new DatCatalogoEstado();
                    oLista=oDatEstado.Buscar(3001);
                    /*out.printf("<option value='%1s'>%2s</option>", "1", "RUC");
                    out.printf("<option value='%1s'>%2s</option>", "2", "DNI");
                    out.printf("<option value='%1s'>%2s</option>", "3", "Pasaporte");*/
                    for(CatalogoEstado ent: oLista){
                        out.printf("<option value='%1s'>%2s</option>", ent.getVal_est_in(), ent.getNom_est_vc());
                    }
                }
            }
            if(request.getParameter("nCliente")!=null){   
                oDatEstado=new DatCatalogoEstado();
                oLista=oDatEstado.Buscar(3000);
                out.printf("<option value='%1s'>%2s</option>", "0", "[Seleccione]");
                for(CatalogoEstado ent: oLista){
                out.printf("<option value='%1s'>%2s</option>", ent.getVal_est_in(), ent.getNom_est_vc());
                }
            }
            
        } finally { 
            out.close();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
